package com.liuyk.commonlib.adapter;

import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
 * 容器fragment adapter基类
 * <p>
 * Created by liuyk on 2019/3/13.
 */
public abstract class BaseStatePagerAdapter<T> extends FragmentStatePagerAdapter {
    private ArrayList<T> mItems;
    private Context mContext;

    public BaseStatePagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        mContext = context;
    }

    public void setChannels(ArrayList<T> channels) {
        this.mItems = channels;
    }

    @NotNull
    @Override
    public Fragment getItem(int position) {
        return Fragment.instantiate(mContext, getFragmentName(), getArgs(position));
    }

    protected abstract String getFragmentName();

    protected abstract Bundle getArgs(int position);

    @Override
    public int getCount() {
        return mItems == null ? 0 : mItems.size();
    }

    public T getDataItem(int position) {
        return mItems == null ? null : mItems.get(position);
    }

    @Override
    public int getItemPosition(@NotNull Object object) {
        return POSITION_NONE;
    }
}
